
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class LinkContactAgencyComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public LinkContactAgencyComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public LinkContactAgency SelectOne(int ContactAgencyId)
        {  
			PlacementManager.DAL.LinkContactAgency_DAL o = new PlacementManager.DAL.LinkContactAgency_DAL();
			o.ContactAgencyId = ContactAgencyId;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.LinkContactAgency LinkContactAgencyToReturn = new PlacementManager.LinkContactAgency((int)row["ContactAgencyId"], (int)row["ContactId"], (int)row["AgencyId"], (decimal)row["Rate"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
				return LinkContactAgencyToReturn;
			}
			else
			{
				PlacementManager.LinkContactAgency LinkContactAgencyToReturnEmpty = new PlacementManager.LinkContactAgency();
                return LinkContactAgencyToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkContactAgency> SelectAll(string sortExpression)
        {
            List<LinkContactAgency> listLinkContactAgency = new List<LinkContactAgency>();
            PlacementManager.DAL.LinkContactAgency_DAL o = new PlacementManager.DAL.LinkContactAgency_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listLinkContactAgency.Add(new LinkContactAgency((int)row["ContactAgencyId"], (int)row["ContactId"], (int)row["AgencyId"], (decimal)row["Rate"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listLinkContactAgency.Sort(new LinkContactAgencyComparer(sortExpression));
            return listLinkContactAgency;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkContactAgency> SelectAllWAgencyId(int AgencyId, string sortExpression)
		{
			List<LinkContactAgency> listLinkContactAgency = new List<LinkContactAgency>();
			PlacementManager.DAL.LinkContactAgency_DAL o = new PlacementManager.DAL.LinkContactAgency_DAL();
			o.AgencyId = AgencyId;
			DataSet ds = o.SelectAllWAgencyId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listLinkContactAgency.Add(new LinkContactAgency((int)row["ContactAgencyId"], (int)row["ContactId"], (int)row["AgencyId"], (decimal)row["Rate"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listLinkContactAgency.Sort(new LinkContactAgencyComparer(sortExpression));
			return listLinkContactAgency;
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkContactAgency> SelectAllWContactId(int ContactId, string sortExpression)
		{
			List<LinkContactAgency> listLinkContactAgency = new List<LinkContactAgency>();
			PlacementManager.DAL.LinkContactAgency_DAL o = new PlacementManager.DAL.LinkContactAgency_DAL();
			o.ContactId = ContactId;
			DataSet ds = o.SelectAllWContactId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listLinkContactAgency.Add(new LinkContactAgency((int)row["ContactAgencyId"], (int)row["ContactId"], (int)row["AgencyId"], (decimal)row["Rate"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listLinkContactAgency.Sort(new LinkContactAgencyComparer(sortExpression));
			return listLinkContactAgency;
		}


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(LinkContactAgency o)
        {	
            PlacementManager.DAL.LinkContactAgency_DAL oLinkContactAgency = new PlacementManager.DAL.LinkContactAgency_DAL();
			oLinkContactAgency.ContactId = o.ContactId;
			oLinkContactAgency.AgencyId = o.AgencyId;
			oLinkContactAgency.Rate = o.Rate;
			oLinkContactAgency.IsActive = o.IsActive;
			oLinkContactAgency.DateCreated = o.DateCreated;
			oLinkContactAgency.CreatedBy = o.CreatedBy;
			oLinkContactAgency.DateUpdated = o.DateUpdated;
			oLinkContactAgency.UpdatedBy = o.UpdatedBy;

            return oLinkContactAgency.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(int ContactId, int AgencyId, decimal Rate, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.LinkContactAgency_DAL oLinkContactAgency = new PlacementManager.DAL.LinkContactAgency_DAL();

			oLinkContactAgency.ContactId = ContactId;
			oLinkContactAgency.AgencyId = AgencyId;
			oLinkContactAgency.Rate = Rate;
			oLinkContactAgency.IsActive = IsActive;
			oLinkContactAgency.DateCreated = DateCreated;
			oLinkContactAgency.CreatedBy = CreatedBy;
			oLinkContactAgency.DateUpdated = DateUpdated;
			oLinkContactAgency.UpdatedBy = UpdatedBy;

            return oLinkContactAgency.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(LinkContactAgency o)
        {	
            PlacementManager.DAL.LinkContactAgency_DAL oLinkContactAgency = new PlacementManager.DAL.LinkContactAgency_DAL();
			oLinkContactAgency.ContactAgencyId = o.ContactAgencyId;
			oLinkContactAgency.ContactId = o.ContactId;
			oLinkContactAgency.AgencyId = o.AgencyId;
			oLinkContactAgency.Rate = o.Rate;
			oLinkContactAgency.IsActive = o.IsActive;
			oLinkContactAgency.DateCreated = o.DateCreated;
			oLinkContactAgency.CreatedBy = o.CreatedBy;
			oLinkContactAgency.DateUpdated = o.DateUpdated;
			oLinkContactAgency.UpdatedBy = o.UpdatedBy;

            return oLinkContactAgency.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int ContactAgencyId, int ContactId, int AgencyId, decimal Rate, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.LinkContactAgency_DAL oLinkContactAgency = new PlacementManager.DAL.LinkContactAgency_DAL();

			oLinkContactAgency.ContactAgencyId = ContactAgencyId;
			oLinkContactAgency.ContactId = ContactId;
			oLinkContactAgency.AgencyId = AgencyId;
			oLinkContactAgency.Rate = Rate;
			oLinkContactAgency.IsActive = IsActive;
			oLinkContactAgency.DateCreated = DateCreated;
			oLinkContactAgency.CreatedBy = CreatedBy;
			oLinkContactAgency.DateUpdated = DateUpdated;
			oLinkContactAgency.UpdatedBy = UpdatedBy;

            return oLinkContactAgency.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(LinkContactAgency o)
        {
            PlacementManager.DAL.LinkContactAgency_DAL oLinkContactAgency_DAL = new PlacementManager.DAL.LinkContactAgency_DAL();
            oLinkContactAgency_DAL.ContactAgencyId = o.ContactAgencyId;
            return oLinkContactAgency_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int ContactAgencyId)
        {
            PlacementManager.DAL.LinkContactAgency_DAL oLinkContactAgency_DAL = new PlacementManager.DAL.LinkContactAgency_DAL();
            oLinkContactAgency_DAL.ContactAgencyId = ContactAgencyId;
            return oLinkContactAgency_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWAgencyId(int AgencyId)
		{
			PlacementManager.DAL.LinkContactAgency_DAL oLinkContactAgency_DAL = new PlacementManager.DAL.LinkContactAgency_DAL();
			oLinkContactAgency_DAL.AgencyId = AgencyId;			
			return oLinkContactAgency_DAL.DeleteAllWAgencyId();
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWContactId(int ContactId)
		{
			PlacementManager.DAL.LinkContactAgency_DAL oLinkContactAgency_DAL = new PlacementManager.DAL.LinkContactAgency_DAL();
			oLinkContactAgency_DAL.ContactId = ContactId;			
			return oLinkContactAgency_DAL.DeleteAllWContactId();
		}

	}
	
	public class LinkContactAgencyComparer : IComparer<LinkContactAgency>
    {
        private string _sortColumn;
        private bool _reverse;

        public LinkContactAgencyComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(LinkContactAgency a, LinkContactAgency b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "ContactAgencyId":
					retVal = String.Compare(a.ContactAgencyId.ToString(), b.ContactAgencyId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "ContactId":
					retVal = String.Compare(a.ContactId.ToString(), b.ContactId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "AgencyId":
					retVal = String.Compare(a.AgencyId.ToString(), b.AgencyId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Rate":
					retVal = String.Compare(a.Rate.ToString(), b.Rate.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
